﻿using FluentNHibernate.Mapping;

namespace ControleRepresentante.Logic.Models.Maps
{
    public class UserMap : MapBase<User>
    {
        public UserMap()
        {
            Table("SystemUser");
            Map(x => x.Password)
                .Not.Nullable();
            Map(x => x.Username)
                .Not.Nullable()
                .Unique();
            Map(x => x.IsAdmin)
                .Not.Nullable();
            Map(x => x.Ativo)
                .Not.Nullable();
            HasMany(x => x.Permissoes)
                .Inverse()
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.AllDeleteOrphan();
            HasManyToMany(x => x.Filtros)
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.None();
            HasMany(x => x.Posts)
                .Inverse()
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.AllDeleteOrphan();
            References(x => x.Representante)
                .Nullable();
            Map(x => x.Email)
                .Nullable();
            HasMany(x => x.IndexColumnsPreferences)
                .Inverse()
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.AllDeleteOrphan();
        }
    }
}